package cn.wolfcode.wolf2w.business.service.impl;

import cn.wolfcode.wolf2w.business.api.RemoteNoteService;
import cn.wolfcode.wolf2w.business.api.domain.Note;
import cn.wolfcode.wolf2w.business.api.domain.NoteEs;
import cn.wolfcode.wolf2w.business.repository.NoteEsRepository;
import cn.wolfcode.wolf2w.business.service.INoteEsService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NoteEsServiceImpl implements INoteEsService {
    @Autowired
    private NoteEsRepository repository;
    @Autowired
    private RemoteNoteService remoteNoteService;

    @Override
    public void initNoteEs() {
        List<Note> list = remoteNoteService.list("inner").getData();
        for (Note note : list) {
            NoteEs es = new NoteEs();
            /**
             * 属性拷贝方法，会将同名属性从source拷贝到target
             * 参数1： source
             * 参数2： target
             * */
            BeanUtils.copyProperties(note, es);
            repository.save(es);
        }
    }
}
